{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd \n",
    "csv_df = pd.read_csv(r'C:\\Users\\sen\\Downloads\\property-data.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "           PID  ST_NUM     ST_NAME OWN_OCCUPIED NUM_BEDROOMS NUM_BATH SQ_FT\n",
      "0  100001000.0   104.0      PUTNAM            Y            3        1  1000\n",
      "1  100002000.0   197.0   LEXINGTON            N            3      1.5    --\n",
      "2  100003000.0     NaN   LEXINGTON            N          NaN        1   850\n",
      "3  100004000.0   201.0    BERKELEY           12            1      NaN   700\n",
      "4          NaN   203.0    BERKELEY            Y            3        2  1600\n",
      "5  100006000.0   207.0    BERKELEY            Y          NaN        1   800\n",
      "6  100007000.0     NaN  WASHINGTON          NaN            2   HURLEY   950\n",
      "7  100008000.0   213.0     TREMONT            Y            1        1   NaN\n",
      "8  100009000.0   215.0     TREMONT            Y           na        2  1800\n"
     ]
    }
   ],
   "source": [
    "print(csv_df)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0    100001000.0\n",
      "1    100002000.0\n",
      "2    100003000.0\n",
      "3    100004000.0\n",
      "4            NaN\n",
      "5    100006000.0\n",
      "6    100007000.0\n",
      "7    100008000.0\n",
      "8    100009000.0\n",
      "Name: PID, dtype: float64\n",
      "0        PUTNAM\n",
      "1     LEXINGTON\n",
      "2     LEXINGTON\n",
      "3      BERKELEY\n",
      "4      BERKELEY\n",
      "5      BERKELEY\n",
      "6    WASHINGTON\n",
      "7       TREMONT\n",
      "8       TREMONT\n",
      "Name: ST_NAME, dtype: object\n"
     ]
    }
   ],
   "source": [
    "# 选则列\n",
    "print(csv_df['PID'])\n",
    "print(csv_df['ST_NAME'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>PID</th>\n",
       "      <th>ST_NUM</th>\n",
       "      <th>ST_NAME</th>\n",
       "      <th>OWN_OCCUPIED</th>\n",
       "      <th>NUM_BEDROOMS</th>\n",
       "      <th>NUM_BATH</th>\n",
       "      <th>SQ_FT</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>100001000.0</td>\n",
       "      <td>104.0</td>\n",
       "      <td>PUTNAM</td>\n",
       "      <td>Y</td>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>1000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>100002000.0</td>\n",
       "      <td>197.0</td>\n",
       "      <td>LEXINGTON</td>\n",
       "      <td>N</td>\n",
       "      <td>3</td>\n",
       "      <td>1.5</td>\n",
       "      <td>--</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>100003000.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>LEXINGTON</td>\n",
       "      <td>N</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1</td>\n",
       "      <td>850</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>100004000.0</td>\n",
       "      <td>201.0</td>\n",
       "      <td>BERKELEY</td>\n",
       "      <td>12</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "      <td>700</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>100006000.0</td>\n",
       "      <td>207.0</td>\n",
       "      <td>BERKELEY</td>\n",
       "      <td>Y</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1</td>\n",
       "      <td>800</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>100007000.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>WASHINGTON</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2</td>\n",
       "      <td>HURLEY</td>\n",
       "      <td>950</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>100008000.0</td>\n",
       "      <td>213.0</td>\n",
       "      <td>TREMONT</td>\n",
       "      <td>Y</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>100009000.0</td>\n",
       "      <td>215.0</td>\n",
       "      <td>TREMONT</td>\n",
       "      <td>Y</td>\n",
       "      <td>na</td>\n",
       "      <td>2</td>\n",
       "      <td>1800</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>NaN</td>\n",
       "      <td>203.0</td>\n",
       "      <td>BERKELEY</td>\n",
       "      <td>Y</td>\n",
       "      <td>3</td>\n",
       "      <td>2</td>\n",
       "      <td>1600</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "           PID  ST_NUM     ST_NAME OWN_OCCUPIED NUM_BEDROOMS NUM_BATH SQ_FT\n",
       "0  100001000.0   104.0      PUTNAM            Y            3        1  1000\n",
       "1  100002000.0   197.0   LEXINGTON            N            3      1.5    --\n",
       "2  100003000.0     NaN   LEXINGTON            N          NaN        1   850\n",
       "3  100004000.0   201.0    BERKELEY           12            1      NaN   700\n",
       "5  100006000.0   207.0    BERKELEY            Y          NaN        1   800\n",
       "6  100007000.0     NaN  WASHINGTON          NaN            2   HURLEY   950\n",
       "7  100008000.0   213.0     TREMONT            Y            1        1   NaN\n",
       "8  100009000.0   215.0     TREMONT            Y           na        2  1800\n",
       "4          NaN   203.0    BERKELEY            Y            3        2  1600"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#按列进行排序\n",
    "csv_df.sort_values(by=['PID'], ascending=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>PID</th>\n",
       "      <th>ST_NUM</th>\n",
       "      <th>ST_NAME</th>\n",
       "      <th>OWN_OCCUPIED</th>\n",
       "      <th>NUM_BEDROOMS</th>\n",
       "      <th>NUM_BATH</th>\n",
       "      <th>SQ_FT</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>100001000.0</td>\n",
       "      <td>104.0</td>\n",
       "      <td>PUTNAM</td>\n",
       "      <td>Y</td>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>1000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>100002000.0</td>\n",
       "      <td>197.0</td>\n",
       "      <td>LEXINGTON</td>\n",
       "      <td>N</td>\n",
       "      <td>3</td>\n",
       "      <td>1.5</td>\n",
       "      <td>--</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>100003000.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>LEXINGTON</td>\n",
       "      <td>N</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1</td>\n",
       "      <td>850</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>100004000.0</td>\n",
       "      <td>201.0</td>\n",
       "      <td>BERKELEY</td>\n",
       "      <td>12</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "      <td>700</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>NaN</td>\n",
       "      <td>203.0</td>\n",
       "      <td>BERKELEY</td>\n",
       "      <td>Y</td>\n",
       "      <td>3</td>\n",
       "      <td>2</td>\n",
       "      <td>1600</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>100006000.0</td>\n",
       "      <td>207.0</td>\n",
       "      <td>BERKELEY</td>\n",
       "      <td>Y</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1</td>\n",
       "      <td>800</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>100007000.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>WASHINGTON</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2</td>\n",
       "      <td>HURLEY</td>\n",
       "      <td>950</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>100008000.0</td>\n",
       "      <td>213.0</td>\n",
       "      <td>TREMONT</td>\n",
       "      <td>Y</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>100009000.0</td>\n",
       "      <td>215.0</td>\n",
       "      <td>TREMONT</td>\n",
       "      <td>Y</td>\n",
       "      <td>na</td>\n",
       "      <td>2</td>\n",
       "      <td>1800</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "           PID  ST_NUM     ST_NAME OWN_OCCUPIED NUM_BEDROOMS NUM_BATH SQ_FT\n",
       "0  100001000.0   104.0      PUTNAM            Y            3        1  1000\n",
       "1  100002000.0   197.0   LEXINGTON            N            3      1.5    --\n",
       "2  100003000.0     NaN   LEXINGTON            N          NaN        1   850\n",
       "3  100004000.0   201.0    BERKELEY           12            1      NaN   700\n",
       "4          NaN   203.0    BERKELEY            Y            3        2  1600\n",
       "5  100006000.0   207.0    BERKELEY            Y          NaN        1   800\n",
       "6  100007000.0     NaN  WASHINGTON          NaN            2   HURLEY   950\n",
       "7  100008000.0   213.0     TREMONT            Y            1        1   NaN\n",
       "8  100009000.0   215.0     TREMONT            Y           na        2  1800"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 按索引排序\n",
    "csv_df.sort_index()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>SQ_FT</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>ST_NAME</th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>BERKELEY</th>\n",
       "      <td>7001600800</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>LEXINGTON</th>\n",
       "      <td>--850</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>PUTNAM</th>\n",
       "      <td>1000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>TREMONT</th>\n",
       "      <td>1800</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>WASHINGTON</th>\n",
       "      <td>950</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                 SQ_FT\n",
       "ST_NAME               \n",
       "BERKELEY    7001600800\n",
       "LEXINGTON        --850\n",
       "PUTNAM            1000\n",
       "TREMONT           1800\n",
       "WASHINGTON         950"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 案列就行分组聚合\n",
    "csv_df.groupby('ST_NAME').agg({'ST_NAME':'count'})\n",
    "# 按列分组求\n",
    "csv_df.groupby('ST_NAME').agg({'SQ_FT':'sum'})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "None\n"
     ]
    }
   ],
   "source": [
    "# 替换\n",
    "repalce_df= csv_df.replace(to_replace='--',value='replace_value',inplace=True)\n",
    "print(repalce_df)\n",
    "# print(csv_df)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "False\n"
     ]
    }
   ],
   "source": [
    "str ='string 字符串'\n",
    "str = '赋值宁一\\\\个字符串'\n",
    "print(' '==None)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "base",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
